<?php
/*
---------------------------------------------------------------------
- 功能描述: 统一入口
- 文件名:index.php
- 版本: 1.0
- 作者:robot
- 编写日期:2014/9/2
- 运行环境:---
- 修改记录:
---------------------------------------------------------------------
*/
/* 设置时区 */
date_default_timezone_set("Asia/Shanghai");

#session_cache_limiter('public'); //启用此句页面将被缓存
session_start();

header("Content-type: text/html; charset=utf-8");

//项目根目录
define('BASE_DIR', realpath(dirname(dirname(__FILE__))) . '/');

try
{
	/* 载入配置 */
	require_once BASE_DIR . 'config/global.inc.php';
	
	/* 载入核心 */
	include_once LIBRARY_DIR . 'Core/MyException.class.php';
	include_once LIBRARY_DIR . 'Func/Common.class.php';
	include_once LIBRARY_DIR . 'Func/Check.class.php';
	require_once LIBRARY_DIR . 'Core/Base.class.php';

	/* 载入变量 */
	require_once BASE_DIR . 'config/VarData.inc.php';
	
	/* 初始化 */
	$application = new Base();
	$application->run();

}
catch(MyException $e)
{
	if(defined("DEBUG_ON") && DEBUG_ON)
	{
		header("Content-type: text/html; charset=utf-8");
		$sMessage = $e->getMessage();
		echo $sMessage;
	}
	else
	{
		error_log($e->getMessage()."\n".var_export(debug_backtrace(), true), 0);
	}
}

//////////////////////////////////////////////


/**
 * 勿删 自动加载类使用
 *
 * @param string $var
 */
function __autoload($sClassName)
{
	if($sClassName == 'Form')
	{
		$file = LIBRARY_DIR . "Core/Form.class.php";
		include $file;
	}
	else
	{
		$aClassList = explode("_", $sClassName);
		$file = LIBRARY_DIR . "source/{$aClassList[1]}/" . $sClassName . ".class.php";
		if(file_exists($file))
		{
			include $file;
		}
		else
		{
			throw new MyException('File [' . $file . '] is not found...');
		}
	}
}

?>